/**
 *  Copyright (C) 2010  Thomas Volk
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package com.googlecode.bookmarks.web.pages;

import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.panel.FeedbackPanel;

import com.googlecode.bookmarks.core.beans.RemoteResource;
import com.googlecode.bookmarks.web.forms.BookmarkForm;

@AuthorizeInstantiation("USER")
public class EditBookmarkPage extends AbstractBookmarkFormPage {
	public class EditBookmarkForm extends BookmarkForm {

		public EditBookmarkForm(String id) {
			super(id);
			setTitle(resource.getTitle());
			setUrl(resource.getUrl());
		}

		@Override
		public final void onSubmit() {
			getResourceService().updateResource(resource.getId(), getUrl(),
					getTitle());
			setResponsePage(new HomePage());
		}
	}

	private final RemoteResource resource;

	public EditBookmarkPage(RemoteResource resource) {
		this.resource = resource;
		final FeedbackPanel feedback = new FeedbackPanel("messages");
		add(feedback);
		add(new EditBookmarkForm("createForm"));
	}

}
